package com.bdqn.tour.servlet.Hzy;

import com.bdqn.tour.service.HzyOrdersService;
import com.bdqn.tour.service.impl.HzyOrdersServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/GetStatusCount")
public class GetStatusCountServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/plain;charset=UTF-8");

        Object user = req.getSession().getAttribute("user");

        if (user != null) {
            int count = new HzyOrdersServiceImpl().getStatusCount();
            resp.getWriter().print(count);
            resp.getWriter().close();
        } else {
            req.getSession().setAttribute("count", 0);
        }
    }
}
